# -*- coding: utf-8 -*-
# @Author   : Claus
# @Time     : 2020/6/30 17:19
# @FileName : 连接redis - 4.py
import time
from redis import ConnectionPool
from redis import StrictRedis


'''
    使用连接池连接redis中的    StrictRedis
'''


start = time.time()
pool = ConnectionPool(host="localhost", port=6379, db=0, decode_responses=True)
db = StrictRedis(connection_pool=pool)
p = db.pipeline()
for i in range(100000):
    # 添加成功返回1，否则返回0，类型是int
    resu = db.sadd("test", f"test - {i}")
    if resu == 1:
        print("添加成功")
    else:
        print("数据已存在")
p_resu = p.execute()
end = time.time()
print(p_resu)
print(f"用时: {end - start}")
